import pandas as pd
from matplotlib import pyplot as plt

df1 = pd.read_excel(r'./data/data2.xls')
df2 = pd.read_excel(r'./data/data2.xls',sheet_name='2月')
# 中文乱码
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.sans-serif'] = ['Heiti TC']
# 数据集 x1  x2 分别对应外环和内环百分比例
x1 = df1['销量']
x2 = df2['销量']
# 每块颜色
colors = ['red', 'yellow', 'slateblue', 'green','magenta','cyan','darkorange','lawngreen','pink','gold']
# 外环
plt.pie(x1,autopct='%.1f%%',radius=1,pctdistance=0.85,colors=colors,
        wedgeprops=dict(linewidth=2,width=0.3,edgecolor='w'))
# 内环
plt.pie(x2,autopct='%.1f%%',radius=0.7,pctdistance=0.7,colors=colors,
        wedgeprops=dict(linewidth=2,width=0.4,edgecolor='w'))
# 图例
legend_text = df1['省']
# 设置图里的标题，位置，去掉图例边框
plt.legend(legend_text,title='地区',frameon=False,bbox_to_anchor=(0.2,0.5))
# 设置x,y刻度一致，保证饼图是圆形
plt.axis('equal')
plt.title('各省销量占比')
plt.show()


